<template>
  <div class="login-container">
    <van-nav-bar
      title="登录页"
      left-text="返回"
      left-arrow
      @click="$router.back()"
    />

    <van-form @submit="onSubmit">
      <van-field
        v-model="mobile"
        name="mobile"
        label="用户名"
        placeholder="请输入手机号"
        required
        :rules="[{ required: true, message: '请填写用户名' },
        {
            pattern: /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/,
            message: '手机号格式不对'
          }
        ]"
      />
      <van-field
        v-model="code"
        type="password"
        name="code"
        label="密码"
        placeholder="请输入验证码"
        required
        :rules="[{ required: true, message: '请填写密码' },
        {
        pattern: /^\d{6}$/,
        message:'验证码格式不对'
        }
        ]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import {userLogin} from '@/utils/axios.js'
export default {
  name: "login",
  data() {
    return {
      mobile: "13437587724",
      code: "246810",
    };
  },
  methods: {
    //点击表单中的按钮触发
    onSubmit(values){
      console.log(values);

      userLogin(values.mobile,values.code).then(res => {
        console.log(res);
      })
    }
  },
};
</script>

<style lang="less">
.login-container {
  .van-nav-bar__content {
    background-color: #009afb;
    .van-nav-bar__title {
      color: #fff;
    }
    .van-nav-bar__text {
      color: #fff;
    }
    .van-icon-arrow-left {
      color: #fff;
    }
  }
}
</style>
